const mongoose = require('mongoose');

// 任务模型定义
const TaskSchema = new mongoose.Schema({
  id: {
    type: String,
    required: true
  },
  name: {
    type: String,
    required: true
  },
  description: String,
  completed: {
    type: Boolean,
    default: false
  },
  progress: {
    type: Number,
    default: 0
  },
  reward: {
    type: Number,
    required: true
  },
  type: {
    type: String,
    enum: ['daily', 'eco', 'challenge', 'long-term'],
    required: true
  },
  deadline: Number
});

// 成就模型定义
const AchievementSchema = new mongoose.Schema({
  id: {
    type: String,
    required: true
  },
  name: {
    type: String,
    required: true
  },
  description: String,
  threshold: {
    type: Number,
    required: true
  },
  icon: String,
  unlocked: {
    type: Boolean,
    default: false
  },
  progress: {
    type: Number,
    default: 0
  },
  reward: String,
  type: {
    type: String,
    enum: ['energy', 'landmark', 'daily', 'special'],
    required: true
  }
});

// 已完成任务历史记录
const CompletedTaskHistorySchema = new mongoose.Schema({
  date: {
    type: String,
    required: true
  },
  tasks: [
    {
      id: String,
      type: String,
      name: String
    }
  ]
});

// 星球数据模型
const PlanetSchema = new mongoose.Schema({
  userId: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'User',
    required: true,
    unique: true
  },
  activeLandmarks: {
    type: [String],
    default: []
  },
  achievements: {
    type: [AchievementSchema],
    default: []
  },
  ecoTasks: {
    type: [TaskSchema],
    default: []
  },
  challengeTasks: {
    type: [TaskSchema],
    default: []
  },
  completedTasksHistory: {
    type: [CompletedTaskHistorySchema],
    default: []
  },
  lastUpdated: {
    type: Date,
    default: Date.now
  }
});

module.exports = PlanetSchema; 